package com.ytc.teaching.controller;

import com.ytc.commons.model.dto.CommentCourseDto;
import com.ytc.commons.model.dto.CommentQueryDto;
import com.ytc.commons.model.dto.PageRequest;
import com.ytc.commons.model.vo.CommentVo;
import com.ytc.commons.model.vo.PageResponseResult;
import com.ytc.commons.model.vo.ResponseResult;
import com.ytc.system.api.SystemClient;
import com.ytc.teaching.service.CommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author jiuye
 */
@Slf4j
@RestController
@RequestMapping("/course-comment")
public class CommentController {

    @Autowired
    private CommentService commentService;
    @Autowired
    private SystemClient systemClient;

    /**
     * 运营平台---删除评论
     */
    @DeleteMapping("/{commentId}")
    public ResponseResult RemoveCommentId(@PathVariable("commentId") Long commentId) {
        commentService.removeById(commentId);
        return ResponseResult.okResult(true);
    }

    /**
     * 运营平台---机构的评论列表
     */
    @GetMapping("/list-all")
    public PageResponseResult<CommentVo> listAll(@SpringQueryMap CommentQueryDto dto, @RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize) {
        return commentService.listAll(dto, pageNo, pageSize);
    }


    /**
     * 机构端=--查询教育机构的评论列表
     */
    @PostMapping("/list")
    public ResponseResult commentList(@RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize, @RequestBody(required = false) CommentQueryDto dto) {
        return commentService.commentList(pageNo, pageSize, dto);
    }

    /**
     * 门户详情页-评论课程
     */
    @PostMapping
    public ResponseResult courseComment(@RequestBody(required = false) CommentCourseDto dto) {
        return commentService.courseComment(dto);

    }

    /**
     * 门户详情页----课程评论列表
     */
    @PostMapping("/for-course")
    public ResponseResult forCourse(PageRequest pageRequest, @RequestBody(required = false) CommentQueryDto dto) {
        return commentService.forCourse(pageRequest, dto);
    }

    /**
     * 门户详情页----课程评论统计
     */
    @GetMapping("/course-statistics/{targetId}")
    public ResponseResult CountTargetId(@PathVariable("targetId") Long targetId) {
        return commentService.CountTargetId(targetId);
    }

    @GetMapping
    public ResponseResult aa(Long id) {
        return systemClient.findById(id);
    }
}
